package com.sybil.spa.servicio;

import com.sybil.spa.dao.CausaDAO;
import com.sybil.spa.dominio.Causa;
import java.util.List;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service("causaServicio")
@Transactional(readOnly = true)
public class CausaServicio {

   @Autowired
   private CausaDAO causaDAO;

   public void guardar(Causa causa) {
      causa.setActivo("S");
      causaDAO.guardarCausa(causa);
   }

   public void editar(Causa causa) {
      causaDAO.editarCausa(causa);
   }

   @Transactional(readOnly = false)
   public void eliminarCausa(String clave) {
      Causa causaParo = causaDAO.getCausa(clave);
      causaDAO.eliminarCausa(causaParo);
   }

   @Transactional(readOnly = false)
   public void inactivarCausa(String clave, String usuario) {
      Causa causaParo = causaDAO.getCausa(clave);
      causaParo.setActivo("N");
      causaParo.setUsuarioModif(usuario);
      causaDAO.editarCausa(causaParo);
   }

   public List<Causa> obtenerCausas() {
      return causaDAO.getCausas(false);
   }

   public List<Causa> obtenerCausasActivas() {
      return causaDAO.getCausas(true);
   }

   public Causa obtenerCausa(String clave) {
      return causaDAO.getCausa(clave);
   }
}
